using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TestScript : MonoBehaviour {
	
	List<Rect> rList;
	Texture2D rectText;
	public int rectCount = 10;
	System.Random rnd = new System.Random();
	
	public Rect zone = new Rect(20,20,250,250);
	Texture2D zoneText;
	

	// Use this for initialization
	void Start () {
		
		rList = new List<Rect>();
		
		rectText = new Texture2D(1,1);
		rectText.SetPixel(0,0,Color.red);
		rectText.Apply();
		zoneText = new Texture2D(1,1);
		zoneText.SetPixel(0,0,Color.grey);
		zoneText.Apply();
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnGUI()
	{
		if(Event.current.type == EventType.repaint)
		{
			Graphics.DrawTexture(zone, zoneText);
			foreach(Rect curRect in rList)
			{
				Graphics.DrawTexture(curRect, rectText);
			}
		}
		
		if(GUILayout.Button("random"))
		{
			
			rList.Clear();
			
			for(int i=0; i<rectCount; i++)
			{
				Rect temp = new Rect();
				temp.x = rnd.Next((int)zone.x, (int)zone.xMax);
				temp.y = rnd.Next((int)zone.y, (int)zone.yMax);
				temp.width = rnd.Next(3,15);
				temp.height = rnd.Next(3,15);
				rList.Add(temp);
			}
		}
	}
}
